﻿using BasicInformationCommon.API.BasicInformationCommons.Materiales;
using ERPSystem.Common.DTO;
using ERPSystem.Enum.CommonErrorCodes;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace BasicInformationCommon.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaterialsController : Controller
    {
        private readonly IMediator mediator;

        public MaterialsController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 物料分类树形
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> GetmaterialTree([FromQuery]MaterialesTreeQueryCommand request, CancellationToken cancellationToken)
        {
            var result = await mediator.Send(request, cancellationToken);
            return result;
        }


        /// <summary>
        /// 物料分类反填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<MaterialclassifyDTO>> GetmaterialfanTian([FromQuery]MaterialesBcakFillCommand request, CancellationToken cancellationToken)
        {
            var result = await mediator.Send(request, cancellationToken);
            return result;
        }

        /// <summary>
        /// 计量单位下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<Result> Getmeasureunits([FromQuery]MeasureunitsQueryCommand request, CancellationToken cancellationToken)
        {
            var result = await mediator.Send(request, cancellationToken);
            return result;
        }

        /// <summary>
        /// 供应方式下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<Result> Getsupplymanners([FromQuery]SupplymannersQueryCommand request, CancellationToken cancellationToken)
        {
            var result = await mediator.Send(request, cancellationToken);
            return result;
        }


        /// <summary>
        /// 物料分类下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<Result> GetClassifyzt([FromQuery]ClassifyztsQueryCommand request, CancellationToken cancellationToken)
        {
            var result = await mediator.Send(request, cancellationToken);
            return result;
        }
        /// <summary>
        /// 处理物料基本信息表查询请求
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<MaterialBasicfileDTO>> MaterialesSearch([FromQuery] MaterialesSearchCommand request, CancellationToken cancellationToken)
        {
           
            try
            {
                var result= await mediator.Send(request);
                return result;  


            }
            catch (Exception)
            {

                throw;
            }
           
        }
    }
}
